var scrollSpeed = 5; //刷新速度
var countX : int = 4; //X轴的图片个数
var countY : int = 4; //Y轴的图片个数
private var offsetX = 0.0;
private var offsetY = 0.0;
private var singleTexSize; //矩形区域
function Start() {
singleTexSize = Vector2(1.0/countX, 1.0/countY);
renderer.material.mainTextureScale = singleTexSize;
}
function Update ()
{
var frame = Mathf.Floor(Time.time*scrollSpeed);
offsetX = frame/countX;
offsetY = -(frame – frame%countX) /countY / countX;
renderer.material.SetTextureOffset (“_MainTex”, Vector2(offsetX, offsetY));
}